#include "common.h"

#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>

int main()
{
	struct dirent *pfile = NULL;

	struct stat st = {0};

	DIR *p = opendir("./");
	if(p == NULL)
		err_sys("Open dir error!\n");

	pfile = readdir(p);
	while(pfile != NULL)
	{
		printf("File Name : '%s'\n", pfile->d_name);
		stat(pfile->d_name, &st);
		if(S_ISREG(st.st_mode))
		{
			printf("Is Regular File.\n");
			printf("Size of file : %ld\n", st.st_size);
		}
		else if(S_ISDIR(st.st_mode))
		{
			printf("Is Dir.\n");
			printf("Size of dir : %ld\n", st.st_size);
		}
		
		printf("\n\n\n");
		pfile = readdir(p);
	}

	
	pfile = readdir(p);

	closedir(p);
	return 0;
}
